package com.test.springCloud.controller;

import com.test.springCloud.service.ExcelService;
import com.test.springCloud.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 导入excel表格、到处excel表格
 */
@Controller
@CrossOrigin  //跨域
@RequestMapping("/lxf")
@Slf4j
public class ExcelController {

    @Resource
    ExcelService excelService;

    /**
     * 批量导入excel表
     * @param file
     * @return
     */
    @PostMapping("/uploadExcel")
    @ResponseBody
    public ResultUtils uploadExcel(@RequestParam("file")MultipartFile file, HttpServletRequest request){
        return excelService.uploadExcel(file,request);
    }

    /**
     * 导出excel表
     * @param request
     * @return
     */
    @PostMapping("/downloadExcel")
    @ResponseBody
    public ResultUtils downloadExcel(HttpServletRequest request){
        return excelService.downloadExcel(request);
    }
}
